#include "onode.h"

ONode::ONode(QObject *parent) :
    BasicObject(parent)
{
    m_node = 0;
    m_xScale = m_zScale = m_yScale = 1;
    m_xPos = m_yPos = m_zPos = 0;
    m_xAng = m_yAng = m_zAng = 0;
    m_parentNodeID = "root";
}

void ONode::updatePos()
{
    if (m_node == 0) return;
    m_node->setPosition(m_xPos, m_yPos, m_zPos);
}

void ONode::updateScale()
{
    if (m_node == 0) return;
    m_node->setScale(m_xScale, m_yScale, m_zScale);
}

QString ONode::parentNodeId() const {
    return m_parentNodeID;
}

void ONode::setParentNodeId(const QString& id) {
    this->m_parentNodeID = id;
}

float ONode::xPos() const {
    return m_xPos;
}

void ONode::setXPos(float pos) {
    this->m_xPos = pos;
        updatePos();
}

float ONode::yPos() const {
    return m_yPos;
}

void ONode::setYPos(float pos) {
    this->m_yPos = pos;
        updatePos();
}

float ONode::zPos() const {
    return m_zPos;
}

void ONode::setZPos(float pos) {
    this->m_zPos = pos;
        updatePos();
}

void ONode::setNode(Ogre::SceneNode* node)
{
    m_node = node;
    updatePos();
    updateScale();
    setXAng(2 * m_xAng);
    setYAng(2 * m_yAng);
    setZAng(2 * m_zAng);
}

float ONode::xScale() const
{
    return m_xScale;
}

float ONode::yScale() const
{
    return m_yScale;
}

float ONode::zScale() const
{
    return m_zScale;
}

void ONode::setXScale(float scale)
{
    m_xScale = scale;
    updateScale();
}

void ONode::setZScale(float scale)
{
    m_zScale = scale;
    updateScale();
}

void ONode::setYScale(float scale)
{
    m_yScale = scale;
    updateScale();
}

float ONode::xAng() const
{
    return m_xAng;
}

float ONode::yAng() const
{
    return m_yAng;
}

float ONode::zAng() const
{
    return m_zAng;
}

void ONode::setXAng(float ang)
{
    float old = m_xAng;
    m_xAng = ang;
    if (m_node == 0) return;
    m_node->pitch(Ogre::Degree(ang - old));
}

void ONode::setYAng(float ang)
{
    float old = m_yAng;
    m_yAng = ang;
    if (m_node == 0) return;
    m_node->yaw(Ogre::Degree(ang - old));
}

void ONode::setZAng(float ang)
{
    float old = m_zAng;
    m_zAng = ang;
    if (m_node == 0) return;
    m_node->roll(Ogre::Degree(ang - old));
}
